export default (value, field, key) => {
  let dicts = window.SITE_CONFIG['dictList'] || []
  if (key) {
    let currentDict = dicts.find(i => i.dictType === key)
    if (currentDict) {
      dicts = [currentDict]
    }
  }

  let current
  for (let i = 0; i < dicts.length; i++) {
    const list = dicts[i].dataList || []
    const obj = list.find(m => m[field] === value)
    if (obj) {
      current = obj
      break
    }
  }

  return current
}

export const useDicts = key => {
  let dicts = window.SITE_CONFIG['dictList'] || []
  let currentDict = dicts.find(i => i.dictType === key)
  if (currentDict) {
    return currentDict.dataList
  }

  return []
}
